package com.krahets88.stack;

import org.junit.jupiter.api.Test;

import java.util.Stack;
import java.util.Vector;

public class Question {
    @Test
    public void test() {
        isValid("{}");
    }

    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<Character>();
        for (char c : s.toCharArray()) {
            if (c == '(' || c == '[' || c == '{') {
                stack.push(c);
                continue;
            }else{
                if (stack.isEmpty()){
                    return false;
                }
                Character top = stack.pop();
                if ((c == ')' && top != '(') || (c == '}' && top != '{') || (c == ']' && top != '[')) {
                    return false;
                }
            }

        }
        return stack.isEmpty();
    }

}
